Skip to content

PKCE configuration - enabled by default #17507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 6.5.x
Choose a base branch
from

Conversation

rohan-naik07
Copy link

@rohan-naik07 rohan-naik07 commented Jul 10, 2025

Fixes gh-16391

PKCE enabled by default for confidential as well as public clients.
Client Authentication method won't affect the PKCE customizer.
PKCE can be disabled using isRequireProofKey() client setting.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 10, 2025
@rohan-naik07 rohan-naik07 changed the base branch from main to 6.5.x July 10, 2025 16:55
@rohan-naik07 rohan-naik07 marked this pull request as ready for review July 14, 2025 14:29
@jgrandja jgrandja added in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: breaks-passivity A change that breaks passivity with the previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 15, 2025
@jgrandja jgrandja self-assigned this Jul 15, 2025
@rohan-naik07
Copy link
Author

Hi @jgrandja ,

Thank you for reviewing my pull request. I noticed that you marked it as "breaks passivity" and self-assigned the related issue.

I want to understand this better so I can improve future contributions. Could you please clarify what aspect of the PR breaks passivity, and how you envision the correct approach? I'm eager to align with the design principles of the project and contribute effectively.

Thanks again for your time and guidance!

Best regards,
Rohan

@jgrandja
Copy link
Contributor

Hi @rohan-naik07. I haven't had time to review your PR but I plan on it next week.

Our process is to self-assign PR's when we review it and the user who submitted the PR is assigned the original issue.

The reason I marked this "breaks-passivity" is because it is a breaking change that needs to be applied. For example, since the required change is for the OAuth2 Client to send PKCE parameters by default, it's possible that the authorization server does not support PKCE and therefore the flow will fail. So what was working previously might stop working with the upgrade to 7.0 because of this change. Does that make sense?

FYI, the reason for this change is OAuth 2.1 recommends/requires PKCE.

@rohan-naik07
Copy link
Author

Ok, that makes sense. Thanks for clarifying my doubts.

Copy link
Contributor

@jgrandja jgrandja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @rohan-naik07. Please see review comments.

Also, please rebase off of main and ensure there is only 1 commit with the changes. Thanks.

@@ -655,6 +655,10 @@ private ClientRegistration create() {
clientRegistration.clientName = StringUtils.hasText(this.clientName) ? this.clientName
: this.registrationId;
clientRegistration.clientSettings = this.clientSettings;
if (this.clientSettings.requireProofKey) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this since clientRegistration.clientSettings is set in previous line with this.clientSettings and only the clientSettings should be used.

private ClientSettings() {

}
private ClientSettings() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this formatting change as only required changes should be applied

@@ -794,6 +790,7 @@ public static final class Builder {
private boolean requireProofKey;

private Builder() {
this.requireProofKey = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this to variable initialization private boolean requireProofKey = true;

@@ -184,8 +183,7 @@ private OAuth2AuthorizationRequest.Builder getBuilder(ClientRegistration clientR
// value.
applyNonce(builder);
}
if (ClientAuthenticationMethod.NONE.equals(clientRegistration.getClientAuthenticationMethod())
|| clientRegistration.getClientSettings().isRequireProofKey()) {
if (clientRegistration.getClientSettings().isRequireProofKey()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public Clients (indicated with ClientAuthenticationMethod.NONE) always require PKCE but with this change it's possible to disable PKCE for Public Clients. Please revert this as the original logic is still correct.

@@ -196,8 +195,7 @@ private OAuth2AuthorizationRequest.Builder getBuilder(ClientRegistration clientR
// value.
applyNonce(builder);
}
if (ClientAuthenticationMethod.NONE.equals(clientRegistration.getClientAuthenticationMethod())
|| clientRegistration.getClientSettings().isRequireProofKey()) {
if (clientRegistration.getClientSettings().isRequireProofKey()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public Clients (indicated with ClientAuthenticationMethod.NONE) always require PKCE but with this change it's possible to disable PKCE for Public Clients. Please revert this as the original logic is still correct.

@@ -293,6 +293,6 @@ spring:

[NOTE]
====
Public Clients are supported using https://tools.ietf.org/html/rfc7636[Proof Key for Code Exchange] (PKCE).
PKCE will automatically be used when `client-authentication-method` is set to "none" (`ClientAuthenticationMethod.NONE`).
https://tools.ietf.org/html/rfc7636[Proof Key for Code Exchange] (PKCE) will be enabled by default for public as well as confidential clients. Refer https://docs.spring.io/spring-security/reference/servlet/oauth2/client/client-authentication.html#oauth2-client-authentication-public[this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this as the original content is still valid

@@ -69,7 +69,8 @@ This information is available only if the Spring Boot property `spring.security.
<15> `(userInfoEndpoint)authenticationMethod`: The authentication method used when sending the access token to the UserInfo Endpoint.
The supported values are *header*, *form*, and *query*.
<16> `userNameAttributeName`: The name of the attribute returned in the UserInfo Response that references the Name or Identifier of the end-user.
<17> [[oauth2Client-client-registration-requireProofKey]]`requireProofKey`: If `true` or if `authorizationGrantType` is `none`, then PKCE will be enabled by default.
<17> [[oauth2Client-client-registration-requireProofKey]]`requireProofKey`: This will by default be `true`, as PKCE will be enabled by default.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the text to:

If true or if clientAuthenticationMethod is none, then PKCE will be enabled.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we stressing enough on the point that PKCE will be also enabled for confidential clients?... Or we don't want to for now

@@ -64,6 +64,22 @@ public static ClientRegistration.Builder clientRegistration2() {
// @formatter:on
}

public static ClientRegistration.Builder publicClientRegistrationWithNoPkce() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this as TestClientRegistrations.clientRegistration() can be used and the caller can simply change builder.clientSettings(updatedClientSettings)

@rohan-naik07 rohan-naik07 force-pushed the pkce-default-config-gh-16391 branch from 4d50c65 to 119e5df Compare August 16, 2025 10:21
@rohan-naik07 rohan-naik07 force-pushed the pkce-default-config-gh-16391 branch from 119e5df to abe7742 Compare August 18, 2025 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: breaks-passivity A change that breaks passivity with the previous release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants